package net.easyjava.test.banzou;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by wxnacy on 16/6/1.
 */
public class Banzou {

    public static void main(String[] args) {
        getData();
//        updateData("1",2);
    }

    public static void getData(){
        Connection conn = null;//DBTools.instance().getConn();
        String sql = "SELECT * FROM BANZOU WHERE aliyun_url = ''";
        PreparedStatement pstmt;

        try {
            pstmt = conn.prepareStatement(sql);
            ResultSet rs = pstmt.executeQuery();
            while(rs.next()){
                long id = rs.getLong("id");
                String url = rs.getString("url");
                String key = null;// AliyunOSSClient.updateByUrl(url);
                if(key != null){
                    updateData(key,id);
                }
                System.out.println("rs.getLong(\"id\") = " + rs.getLong("id"));
                System.out.println("rs.getString(\"url\") = " + rs.getString("url"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void updateData(String url,long id){
        Connection conn = null;// DBTools.instance().getConn();
        String sql = "UPDATE BANZOU SET aliyun_url = ? WHERE id = ?";
        PreparedStatement pstmt;

        try {
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1,url);
            pstmt.setLong(2,id);
            pstmt.execute();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
